package android.tong;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class TableLayoutDemo extends Activity implements OnClickListener {

	private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		RelativeLayout r_Layout = new RelativeLayout(this);
		setContentView(r_Layout);
		TableLayout tableLayout = new TableLayout(this);
		r_Layout.addView(tableLayout, new RelativeLayout.LayoutParams(WC, WC));
		tableLayout.setId(1);
		
		TableRow tableRow1 = new TableRow(this);
		ImageView iv = new ImageView(this);
		tableRow1.addView(iv);
		iv.setImageDrawable(getResources().getDrawable(R.drawable.android));
		EditText edit1 = new EditText(this);
		tableRow1.addView(edit1);
		tableLayout.addView(tableRow1, new TableLayout.LayoutParams(WC, WC));
		
		TableRow tableRow2 = new TableRow(this);
		ImageView iv2 = new ImageView(this);
		iv2.setImageDrawable(getResources().getDrawable(R.drawable.girlandroid));
		tableRow2.addView(iv2);
		EditText edit2 = new EditText(this);
		tableRow2.addView(edit2);
		tableLayout.addView(tableRow2, new TableLayout.LayoutParams(WC, WC));
		
		Button btn = new Button(this);
		btn.setText("Exit");
		btn.setOnClickListener(this);
		RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(WC, WC);
		param.addRule(RelativeLayout.BELOW, 1);
		param.topMargin = 20;
		r_Layout.addView(btn, param);
		
		TableRow tableRow3 = new TableRow(this);
		TextView tv1 = new TextView(this);
		tv1.setText("Linda");
		TextView tv2 = new TextView(this);
		tv2.setText("0936-3456780");
		tableRow3.addView(tv1);
		tableRow3.addView(tv2);
		tableLayout.addView(tableRow3);
		//r_Layout.addView(tableLayout, new TableLayout.LayoutParams(WC, WC));
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		finish();
	}
	
}
